$(document).ready(function() {
	var addToRankBody = function(response) {
		$('div[id^=rank_info_id_]').unbind();
		$('#dishes_bd').html(response);
		var dishesRankInfoDiv = $('div[id^=rank_info_id_]');
		for (var i = 0; i < dishesRankInfoDiv.length; i++) {
			var rankExtendDiv = $(dishesRankInfoDiv[i]).prev('div[id^=rank_ex_id_]');
			mouseoverDish($(dishesRankInfoDiv[i]), rankExtendDiv);
		}
	};
	
	var showRankDishes = function(rankKindId) {
		var rankBodyHtml = locache.session.get('dish.rank.' + rankKindId);
		if (rankBodyHtml) {
			addToRankBody(rankBodyHtml);
		} else {
			$.get('dishrank/' + rankKindId, function(response){
				addToRankBody(response);
				locache.session.set('dish.rank.' + rankKindId, response, 100);
			});
		}
	};

	var changeBgImg = function(specialObj) {
		$('.rank_menu_ul li').css('background-image', 'url("img/rank/menuwhite.gif")');
		specialObj.css('background-image', 'url("img/rank/menucolor.gif")');
	}

	$('.rank_menu_ul li').mouseenter(function(){
		var rankKindId = $(this).children('param').val();
		changeBgImg($(this));
		showRankDishes(rankKindId);
	});

	var rankKindId = $(this).children('param').val();
	var firstLiMenu = $($('.rank_menu_ul li')[0]);
	showRankDishes(firstLiMenu.children('param').val());
	changeBgImg(firstLiMenu);
});